package com.yanqu.road.server.cmd.inn;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.inn.InnEndCookResult;
import com.yanqu.road.pb.inn.InnProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.inn.InnModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_INN_COOK_END, desc = "结束烹饪")
public class InnCookEndCmd extends AbstractCommand {

    InnEndCookResult result;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!SystemOpenMgr.systemOpen(player, eSystemId.Inn.getValue())) {
            result.setRet(GameErrorCode.E_SYSTEM_NO_OPEN);
            return;
        }
        result = player.getModule(InnModule.class).getCookReword();

    }

    @Override
    public void sendData(GamePlayer player) {
        InnProto.InnCookEndRspMsg.Builder respMsg = InnProto.InnCookEndRspMsg.newBuilder();
        InnProto.InnDetailInfoMsg innInfo = player.getModule(InnModule.class).getInnInfo();
        if (result.getRet() == 0 && innInfo != null) {
            respMsg.setInnDetailInfo(innInfo);
            if(result.getReward() != null){
                respMsg.setReward(result.getReward());
            }
            respMsg.setScoreLevel(result.getScoreLevel());
            respMsg.setScore(result.getScore());
        }
        respMsg.setRet(result.getRet());
        player.sendPacket(Protocol.U_INN_COOK_END, respMsg);
    }
}
